package com.work.studio.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.FutureTarget;
import com.bumptech.glide.request.RequestOptions;
import com.work.studio.R;


public class GlideUtils {

    public static void loadImage(String imageUrl, ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.drawable.default_image).error(R.drawable.default_image).fallback(R.drawable.default_image);
        try {
            Glide.with(imageView.getContext())
                    .load(imageUrl)
                    .dontAnimate()
                    .apply(options)
                    .into(imageView);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Bitmap getBitmap(String imageUrl, Context context) {



        FutureTarget<Bitmap> bitmap = Glide.with(context)
                .asBitmap()
                .load(imageUrl)
                .placeholder(R.drawable.default_image)
                .error(R.drawable.default_image)
                .override(52, 52)
                .submit();
        try {
            return bitmap.get();
        } catch (Exception e) {
            Log.e("bitmap-glide", e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

}
